package com.asset.service;

import com.asset.entity.Asset;
import com.asset.entity.User;
import com.asset.mapper.AssetMapper;
import com.asset.mapper.UserMapper;
import com.asset.vo.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@Service
public class IndexService {
	@Autowired
	private UserService userService;
@Autowired
	UserMapper userMapper;
@Autowired
AssetMapper assetService;
	public AjaxJson index(HttpServletRequest request ,String year) {
		// 创建一个AjaxJson对象
		AjaxJson ajaxJson = new AjaxJson();
		// 获取当前会话
		HttpSession session = request.getSession();
		// 从会话中获取用户信息
		User user = (User) session.getAttribute("user");
		// 打印用户信息
		System.out.println(user);
		// 获取用户ID
		Integer id = user.getId();
		// 将用户ID转换为字符串，并在前后添加逗号
	String  id1= ","+ id;
	String id2 = id + ",";
		// 调用userMapper的getIdByAll_headerIntegers方法，获取用户的所有头衔ID
		ArrayList<Integer> idByAllHeaderIntegers =
				userMapper.getIdByAll_headerIntegers(id1, id2, String.valueOf(id));
		// 调用assetService的getAssetList方法，获取用户的所有资产列表
		ArrayList<Asset> assetList = assetService.getAssetList( idByAllHeaderIntegers);
       // 将资产列表放入AjaxJson对象中
       ajaxJson.putData("assetList", assetList);
		// 调用assetService的getSumAssetBy0方法取到期限的资产数量
		Integer sumAsset0 = assetService.getSumAssetBy0(idByAllHeaderIntegers);
		// 调用assetService的getSumAsset方法，获取用户的所有资产总额
		Integer sumAsset = assetService.getSumAsset(idByAllHeaderIntegers);
		// 调用assetService的getSumAssetByType方法，获取用户的所有资产空闲
		Integer sumAssetByType = assetService.getSumAssetByType(idByAllHeaderIntegers, 1);
		// 调用assetService的getSumAssetByType方法，获取用户的所有资产在用
		Integer sumAssetByType1 = assetService.getSumAssetByType(idByAllHeaderIntegers, 2);
		// 调用assetService的getSumAssetByType方法，获取用户的所有资产封存
		Integer sumAssetByType2 = assetService.getSumAssetByType(idByAllHeaderIntegers, 3);
		// 调用assetService的getSumAssetByType方法，获取用户的所有资产处置
		Integer sumAssetByType3 = assetService.getSumAssetByType(idByAllHeaderIntegers, 4);
		// 调用assetService的getSumAssetByType方法，获取用户的所有资产	维修
		Integer sumAssetByType4 = assetService.getSumAssetByType(idByAllHeaderIntegers, 5);
		// 调用assetService的getSumAssetByType方法，获取用户的所有资产待处置
		Integer sumAssetByType5 = assetService.getSumAssetByType(idByAllHeaderIntegers, 6);
		// 调用assetService的getSumAssetByOne方法，获取用户的所有还有一个月到器
		Integer sumAssetByOne = assetService.getSumAssetByOne(idByAllHeaderIntegers);
		// 调用assetService的getSumAssetByYearAndNew方法，获取用户的这年的新增资产
		Integer sumAssetByYearAndNew = assetService.getSumAssetByYearAndNew(idByAllHeaderIntegers, year);
		// 调用assetService的getSumAssetByYearAndOld方法，获取用户的所有资产这年的报废资产
		Integer sumAssetByYearAndOld = assetService.getSumAssetByYearAndDeath(idByAllHeaderIntegers, year);
		// 调用assetService的getSumAssetByYearAndWaitDeath方法，获取用户的所有这年的等待报废资产
		Integer sumAssetByYearAndWaitDeath = assetService.getSumAssetByYearAndWaitDeath(idByAllHeaderIntegers, year);
		Double manyAssetNew = assetService.getManyAssetByYearAndNew(idByAllHeaderIntegers, year);
		Double manyAssetOld = assetService.getManyAssetByYearAndDeath(idByAllHeaderIntegers, year);
		Double manyAssetNew1 = assetService.getManyAssetByYearAndWaitDeath(idByAllHeaderIntegers, year);
		// 将获取到的数据放入AjaxJson对象中
		ajaxJson.putData("sumAsset0", sumAsset0);
		ajaxJson.putData("sumAsset", sumAsset);
		ajaxJson.putData("sumAssetByType1", sumAssetByType);
		ajaxJson.putData("sumAssetByType2", sumAssetByType1);
		ajaxJson.putData("sumAssetByType3", sumAssetByType2);
		ajaxJson.putData("sumAssetByType4", sumAssetByType3);
		ajaxJson.putData("sumAssetByType5", sumAssetByType4);
		ajaxJson.putData("sumAssetByType6", sumAssetByType5);
		ajaxJson.putData("sumAssetByOne", sumAssetByOne);
		ajaxJson.putData("sumAssetByYearAndNew", sumAssetByYearAndNew);
		ajaxJson.putData("sumAssetByYearAndOld", sumAssetByYearAndOld);
		ajaxJson.putData("sumAssetByYearAndWaitOld", sumAssetByYearAndWaitDeath);
		ajaxJson.putData("manyAssetNew", manyAssetNew);
		ajaxJson.putData("manyAssetOld", manyAssetOld);
		ajaxJson.putData("manyAssetNew1", manyAssetNew1);
		// 返回AjaxJson对象
		return ajaxJson;
	}
}
